#!/usr/bin/python
# -*- coding: UTF8 -*-

from selenium.webdriver.firefox.webdriver import WebDriver
from selenium import webdriver
import time

class qipru:

	def addPost(self, proxy, account, post):
		try:

			if(proxy == True):

				PROXY_HOST = "127.0.0.1"
				PROXY_PORT = 8118

				fp = webdriver.FirefoxProfile()

				# Direct = 0, Manual = 1, PAC = 2, AUTODETECT = 4, SYSTEM = 5
				fp.set_preference("network.proxy.type", 1)

				fp.set_preference("network.proxy.http", PROXY_HOST)
				fp.set_preference("network.proxy.http_port", PROXY_PORT)
				fp.set_preference("network.proxy.ftp", PROXY_HOST)
				fp.set_preference("network.proxy.ftp_port", PROXY_PORT)
				fp.set_preference("network.proxy.ssl", PROXY_HOST)
				fp.set_preference("network.proxy.ssl_port", PROXY_PORT)

				fp.set_preference("network.proxy.no_proxies_on", "") # set this value as desired

				#driver = webdriver.Firefox(firefox_profile=fp)



				driver = webdriver.Firefox(firefox_profile=fp) # Get local session of firefox
			else:
				driver = webdriver.Firefox()



			#driver = webdriver.Firefox()
			driver.implicitly_wait(30)

			driver.get("http://pda.mblogi.qip.ru/")
			driver.find_element_by_id("login").click()
			driver.find_element_by_id("login").send_keys(account[0])
			driver.find_element_by_id("passw").click()
			driver.find_element_by_id("passw").clear()
			driver.find_element_by_id("passw").send_keys(account[1])
			driver.find_element_by_css_selector("input.button_med").click()
			time.sleep(5)
			driver.find_element_by_id("text").clear()
			driver.find_element_by_id("text").send_keys(post)
			driver.find_element_by_id("post_msg_submit").click()
			time.sleep(7)
			driver.close()
			
			return True

		except :

			driver.close()
			return False